<?php

class form_builder
{		
	function form()
	{
		$this->form = "";
	}
	
	function newForm($name,$action,$style="",$class="")
	{
		$form = "<form action='$action' method='post' name='$name' style='$style' class='$class'>";
		$form .= "<table>";
		
		$this->form = $form;
	}
	
	function newLoginForm($name,$style="",$class="")
	{
		$form = "<form action='".$_SERVER['PHP_SELF']."' method='post' name='$name' style='$style' class='$class'>";
		$form .= "<table>";
		$form .= "<tr>
					<td>
						<p>Username :</p>
					</td>
					<td>
						<input type='text' name='username' id='username' value='' placeholder='Enter User Name'>
					</td>
				  </tr>
				  <tr>
				    <td>
				        <p>Password :</p>
				    </td>	
					<td>
						<input type='password' name='password' id='password' value=''>
					</td>
					
				  </tr>
				  <tr>
				  	<td>
				  	</td>
				  	<td>
				  		<input type='submit' id='submit' name='submit' value='Login'>
				  	</td>
				  </tr>	
				  </table>
				  </form> 	";
		$this->form = $form;
		$this->formShow();
		
	}
	
	function closeForm()
	{
		$this->form .= "</table></form>";
	}
	
	function addElement($type,$value,$name,$left_value="",$style='')
	{
		$element = "";
		$element .= "<tr>";
		if ($left_value != "")
		{
			$element .= "<td style='min-width:100px'><p>$left_value</p></td>";	
			$element .= "<td style='min-width:100px'><input type='$type' value='$value' name='$name' id='$name' style='$style' /></td>";
		}
		else
		{		
			$element .= "<td></td><td style='min-width:100px'><input type='$type' value='$value' name='$name' id='$name' style='$style' /></td>";
		}
		$element .= "</tr>";
		$this->form .= $element;
	}
	
	function validate()
	{
		$retval = false;
		if (isset($_REQUEST['submit']))
		{
			$retval = true;
		}
		
		return $retval;
	}
	
	function formShow()
	{
		$this->closeForm();
		echo $this->form;
	}
}
?>